import {reqCategory} from '../../api/index'

Page({
  data:{
    categoryL1List:[],
    categoryGroupList:[],
    currentCategory:{},
    category1Id:11,
    picUrl:''
  },
  onShow(){
    this.getCategory(11)
    this.setData({category1Id:11})
  },
  async getCategory(categoryId){
    try {
      const res = await reqCategory(categoryId)
      this.setData({
        categoryL1List:res.data.categoryL1List,
        currentCategory:res.data.currentCategory,
        picUrl:res.data.currentCategory.bannerList[0].picUrl,
        categoryGroupList:res.data.categoryGroupList
      })
    } catch (error) { 
      console.log(error)
      wx.showToast({
        title:'获取分类失败',
        icon:'error'
      })
    }
  },
  changeActive(e){
    this.setData({
      category1Id:e.target.dataset.id
    })
    this.getCategory(this.data.category1Id)
  }
})